@isTest
private class BindOppoturnityControllerTest {
    static testMethod void testMethod1() {
        Province__c pro = TestUtils.createProvince();
        insert pro;

        City__c c = TestUtils.createCity();
        c.Province__c = pro.Id;
        insert c;

        District__c d = TestUtils.createDistrict();
        d.City__c = c.Id;
        insert d;

        Account acc = TestUtils.createAccount();
        acc.Level__c = '一级医院';
        acc.Name = '客户A';
        acc.Province__c = pro.Id;
        acc.City__c = c.Id;
        acc.District__c = d.Id;
        acc.RecordTypeId = Utils.getRecordTypeIdByDevNameAndObjName('TerminalCustomer','Account');
     
        acc.SpecialDepart__c = '内科_呼吸内科; 内科_神经内科';
        acc.CustomerAttribute__c = '公立医疗机构';



        acc.Postcode__c = '610000';
        acc.BedNumAuthorize__c = 100;
        acc.BedNumOpen__c = 100;
        acc.LastYearRevenue__c = 5000;
        insert acc;


         // 联系人补充
        Contact con1 = TestUtils.createContact();
        con1.LastName = '测试采购科';
        con1.AccountId = acc.Id;
        insert con1;

        Contact con2 = TestUtils.createContact();
        con2.LastName = '测试分管院长';
        con2.Post__c = '分管院长(设备)';
        con2.Departments__c = '医院办公室';
        con2.AccountId = acc.Id;
        insert con2;

        Contact con3 = TestUtils.createContact();
        con3.LastName = '测试财务';
        con3.Post__c = '科长/主任';
        con3.Departments__c = '财务科/计财处';
        con3.AccountId = acc.Id;
        insert con3;

        Contact con4 = TestUtils.createContact();
        con4.LastName = '测试检验';
        con4.Post__c = '科长/主任';
        con4.Departments__c = '检验科';
        con4.AccountId = acc.Id;
        insert con4;

         Account acc1 = TestUtils.createAccount();
        acc1.name = '迈克实业测试';
        acc1.Level__c = '一级医院';
    	acc1.Province__c = pro.Id;
        acc1.City__c = c.Id;
        acc1.District__c = d.Id;
        acc1.RecordTypeId = Utils.getRecordTypeIdByDevNameAndObjName('Maccura','Account');
        insert acc1;


          Brand__c brand = new Brand__c(
            BrandShortName__c = '四川迈克'
        );
        insert brand;
          //产品结构
        ProductStructure__c ps1=new ProductStructure__c();
        ps1.Name='仪器';
        ps1.Classify1__c='生化';
        ps1.Classify2__c='生化-设备';
        ps1.Classify3__c='仪器';
        insert ps1;


        //产品1  
        Product__c p1 = TestUtils.createProduct();
        p1.Purpose__c = '试剂报价用';
        p1.Category1__c = '微生物';   
        p1.RecordTypeId = Utils.getRecordTypeIdByDevNameAndObjName('NCProduct', 'Product__c') ;
        Product__c p2 = TestUtils.createProduct();
        p2.Name = 'Test1';
        p2.Category1__c = '免疫';
        p2.Purpose__c = '试剂报价用';
        p2.RecordTypeId = Utils.getRecordTypeIdByDevNameAndObjName('NCProduct', 'Product__c') ;
        insert new Product__c[] {p1, p2};


        

         // 科室上年度收入
        Department__c dept = [select Id from Department__c where TerminalCustomer__c = :acc.Id];
        dept.LastYearRevenue__c = 1000;
        dept.PurchasingCost__c = 1000;
        update dept;

        Opportunity opp = TestUtils.createOpportunity();
        opp.AccountId = acc.Id;
        opp.StageCanChange__c = '意向';
        opp.StageName = '意向';
    	opp.ExecuteCompany__c = acc1.Id;
        opp.ExecutiveCompany__c = acc1.Id;
         insert opp;

 // 意向产品
        IntentProduct__c ip = TestUtils.createIntentProduct();
        ip.Opportunity__c = opp.Id;
        ip.Product__c = p1.Id ;

        insert ip;

 		opp.StageName = '立项';
        update opp;
         opp.StageCanChange__c = '立项';
         update opp;
       	

        opp.StageName = '方案谈判';
        opp.WinRatio__c = 4;
        opp.PurchaseRoot__c = '公开招标';
        update opp;
         opp.StageCanChange__c = '方案谈判';
         update opp;

         opp.StageName = '招标';
        update opp;

 		opp.StageCanChange__c = '招标';
         update opp;


          ///合同
        Contract__c c1 = new Contract__c();
        c1.name = '测试合同';
        c1.Account__c = acc.Id;
        c1.Corpcode__c = 'MKSY';
        c1.TerminalCustomer__c = acc.Id; 
        insert c1;

        BindOppoturnityController boc = new BindOppoturnityController();
        boc.soId = c1.Id;
        boc.getAccounId();
        boc.getOppList();
        boc.save();
        boc.seledOpp = opp.Id;
        boc.save();


    }
}